rank of word in permutation with repetition